/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __DATA_STRUCT_MODULE_H__
#define __DATA_STRUCT_MODULE_H__

#include "../tools/head.h"

namespace xos_http
{
    class path;
    class file;

    class module : public xos_stl::mem_item< xos::release_impl<module>, thread_lock >,
        public xos::i_release
    {
    public:
        typedef xos::release_impl<module> T;

    public:
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
        static int get_xos_item_data( ITEM_DATA*& item_ptr );

    public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
        http::i_servlet_mgr * m_pServletMgr;
        xos::i_dynamic * m_pServletModule;
        xos_box::i_lock_num * m_pNum;
        bool m_bDeleteFileWhenClose;
        file * m_pFile;

        std::string m_full_path;
        std::string m_full_file;
        std::string m_full_uri;
        std::string m_uri_path;
        std::string m_file;
        std::string m_name;
        std::string m_id;
        std::string m_ext;
        int64_t m_mTime;

    public:
        module();
        ~module();

    protected:
        int delete_module_file() const;
        int init_data();
        
    public:
        int find_and_create_dir_by_uri_path();
        int split_file_ext();
        int fmt_file_name();

        int close_servlet();
        int load_servlet();

        int proc_file();

        int release_ref();
        int add_ref();

        int init();
        int term();
        
    };

} // xos_http

#endif // __DATA_STRUCT_MODULE_H__
